package com.flame.workflow.re.service;

import com.flame.workflow.re.entity.FormComponent;
import com.flame.workflow.re.mapper.FormComponentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * flame_workflow_re_form_item 流程表单项定义表
 *
 * @author 吴欣童
 * @since 2023-05-04 19:53:45
 */
@Service
public class FormComponentService {

    @Autowired
    private FormComponentMapper formComponentMapper;

    public List<FormComponent> getFormComponentList(Long modelId, Integer modelVersion) {
        return formComponentMapper.listByModelId(modelId, modelVersion);
    }

    public void maintainItemList(Long modelId, Integer modelVersion, List<FormComponent> formComponentList) {
        formComponentMapper.deleteByModelId(modelId, modelVersion);
        for (FormComponent formComponent : formComponentList) {
            formComponent.setModelVersion(modelVersion);
            formComponentMapper.insert(formComponent);
        }
    }
}
